<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>23本软件工程2班专属摇号码抽奖页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            background-image: url(微信头像.jpg); 
            background-size: 35% ; /* 覆盖整个背景 */
            background-position: center;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            text-align: center;
            background-color: rgba(255, 255, 255, 0.9); /* 半透明背景 */
            padding: 50px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            width: 300px;
            animation: fadeIn 1s ease-in-out;
        }
        h1 {
            color: #333;
        }
        .number-display {
            font-size: 48px;
            margin-bottom: 20px;
            color: #ff6347;
            animation: flash 0.5s infinite alternate;
        }
        button {
            background-color: #ff6347;
            color: white;
            border: none;
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            border-radius: 5px;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #e9544b;
        }
        .link-container {
            margin-top: 20px;
        }
        a {
            text-decoration: none;
            color: #ff6347;
            font-weight: bold;
        }
        a:hover {
            text-decoration: underline;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        @keyframes flash {
            from { transform: scale(1); }
            to { transform: scale(1.1); }
        }
        .bg-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(255, 255, 255, 0.2); /* 半透明白色覆盖层 */
            z-index: -1;
        }
    </style>
</head>
<body>
    <div class="bg-overlay"></div>
    <div class="container">
        <h1>23本软件工程2班专属摇号码抽奖页面</h1>
        <div class="number-display" id="numberDisplay">--</div>
        <button onclick="startDrawing()">金手指点击抽奖</button>
        <div class="link-container" id="linkContainer"></div>
    </div>

    <script>
        let drawnNumbers = [];
        const totalNumbers = 52;
        let drawCount = 0;

        function getRandomNumber() {
            let randomNumber;
            do {
                randomNumber = Math.floor(Math.random() * totalNumbers) + 1;
            } while (drawnNumbers.includes(randomNumber));
            return randomNumber;
        }

        async function startDrawing() {
            document.getElementById('numberDisplay').innerText = '--';
            const numberDisplay = document.getElementById('numberDisplay');
            const linkContainer = document.getElementById('linkContainer');

            // Clear previous links
            linkContainer.innerHTML = '';

            for (let i = 0; i < 10; i++) {
                await new Promise(resolve => setTimeout(resolve, 100));
                if (drawCount === 4 && i >= 8) {
                    // On the fifth draw, gradually approach 30
                    numberDisplay.innerText = [29, 30][i - 8];
                } else {
                    numberDisplay.innerText = getRandomNumber();
                }
            }

            const finalNumber = numberDisplay.innerText;
            drawnNumbers.push(parseInt(finalNumber));
            drawCount++;

            // Fetch the URL from server
            try {
                const response = await fetch(`/get-link?number=${finalNumber}`);
                if (!response.ok) throw new Error('Network response was not ok');
                const data = await response.json();
                const linkElement = document.createElement('a');
                linkElement.href = data.url;
                linkElement.target = '_blank';
                linkElement.textContent = `中奖链接: ${data.url}`;
                linkContainer.appendChild(linkElement);
            } catch (error) {
                console.error('There was a problem with the fetch operation:', error);
            }
        }
    </script>
</body>
</html>



